package com.sheep.classroompie.controller;


import com.sheep.classroompie.entity.Course;
import com.sheep.classroompie.entity.Exam;
import com.sheep.classroompie.entity.Question;
import com.sheep.classroompie.entity.SubmitExam;
import com.sheep.classroompie.service.ExamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin("http://localhost:8080")
@RequestMapping("/exam")
public class ExamController {
  @Autowired
  ExamService examService;
  @RequestMapping("/addExam")
  @ResponseBody
  public Boolean addExam(@RequestBody Exam exam){
    return examService.addExam(exam);
  }

  @RequestMapping("selectQuestionById")
  @ResponseBody
  Question selectQuestionById(@RequestBody Question question){
    return examService.selectQuestionById(question.getQuestionId());
  }

  @RequestMapping("selectExamsByCourseId")
  @ResponseBody
  List<Exam> selectExamsByCourseId(@RequestBody Course course){
    return examService.selectExamsByCourseId(course.getCourseId());
  }

  @RequestMapping("selectExamById")
  @ResponseBody
  public Exam selectExamById(@RequestBody Exam exam){
    return examService.selectExamById(exam.getExamId());
  }

  @RequestMapping("submitExam")
  @ResponseBody
  public void submitExam(@RequestBody SubmitExam submitExam){
    examService.submitExam(submitExam);
  }

  @RequestMapping("selectSubmitExamsByCourseId")
  @ResponseBody
  public List<SubmitExam> selectSubmitExamsByCourseId(@RequestBody SubmitExam submitExam){
    return examService.selectSubmitExamsByCourseId(submitExam);
  }
//  @RequestMapping("selectExamById")
//  @ResponseBody
//  public SubmitExam selectExamById(@RequestBody SubmitExam submitExam){
//    return examService.selectExamById(submitExam);
//  }
}
